package org.apache.lucene.ocean.name;

import java.io.Serializable;
import java.net.InetSocketAddress;
import java.rmi.Remote;

/**
 * Name service interface.  Primarily responsible for retrieving and updating
 * node information.
 *
 */
public interface NameService extends Remote {
  public Node[] getNodesByCell(String cellId) throws Exception;
  
  public void updateNode(Node node) throws Exception;
  
  /**
   * All cell nodes for a name service
   */
  public static class NameCellNodes implements Serializable {
    public final CellNodes[] cellNodesArray;

    public NameCellNodes(CellNodes[] cellNodesArray) {
      this.cellNodesArray = cellNodesArray;
    }
  }
  
  public static class CellNodes implements Serializable {
    public final String id;
    public final Node[] nodes;
    
    public CellNodes(String id, Node[] nodes) {
      this.id = id;
      this.nodes = nodes;
    }
  }
  
  public static class Node implements Serializable {
    // statuses
    public static final String ONLINE = "online";
    public static final String OFFLINE = "offline";
    public final String id;
    public final String cellId;
    public final InetSocketAddress addr;
    public final String status;
    
    public Node(String id, String cellId, InetSocketAddress addr, String status) {
      this.id = id;
      this.cellId = cellId;
      this.addr = addr;
      this.status = status;
    }
  }
}
